// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   SET_CEImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CE;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.IVL_CE;
import com.sunwayhorizo.health.hl7.datatypes.SET_CE;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            SETCommonImpl, ANYImpl, BLImpl, CEImpl, 
//            CSImpl, STImpl, TYPEImpl, UIDImpl

public class SET_CEImpl extends SETCommonImpl
    implements SET_CE
{

    public static final String RCS_ID = "$Header: SET_CEImpl.java 115.20 2005/09/16 09:23:51 amchanda noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: SET_CEImpl.java 115.20 2005/09/16 09:23:51 amchanda noship $", "oracle.apps.ctb.hl7.types.common");
    private static final SET_CE nullNI = new SET_CEImpl(CSImpl.valueOf("NI"));
    private static final SET_CE nullOTH = new SET_CEImpl(CSImpl.valueOf("OTH"));
    private static final SET_CE nullNINF = new SET_CEImpl(CSImpl.valueOf("NINF"));
    private static final SET_CE nullPINF = new SET_CEImpl(CSImpl.valueOf("PINF"));
    private static final SET_CE nullUNK = new SET_CEImpl(CSImpl.valueOf("UNK"));
    private static final SET_CE nullASKU = new SET_CEImpl(CSImpl.valueOf("ASKU"));
    private static final SET_CE nullNAV = new SET_CEImpl(CSImpl.valueOf("NAV"));
    private static final SET_CE nullMSK = new SET_CEImpl(CSImpl.valueOf("MSK"));
    private static final SET_CE nullNA = new SET_CEImpl(CSImpl.valueOf("NA"));
    private static final SET_CE nullNASK = new SET_CEImpl(CSImpl.valueOf("NASK"));

    public static SET_CE valueOf(CE ace[])
    {
        return new SET_CEImpl(ace);
    }

    public static SET_CE valueOf(CE ce)
    {
        return new SET_CEImpl(ce);
    }

    public static SET_CE nullSET_CE()
    {
        return new SET_CEImpl(((CS) (null)));
    }

    /**
     * 修改CD类型数据改变后带来的错误
     *    /** //2012 10 23 注释
     * jinzw
     * 2010-11-15
     * @param etsservice
     * @param as
     * @return
     * @throws ETSException
     */
//    public static SET_CE newSET_CE(ETSService etsservice, String as[])
//        throws ETSException
//    {
//        List<DictionaryDTO> aconcept  = etsservice.findConcepts(as, true);
//   
//        CE ace[] = new CE[aconcept.size()];
//        for(int i = 0; i < aconcept.size(); i++)
//        {
//        	DictionaryDTO dto = (DictionaryDTO)aconcept.get(i);
//            if(dto != null)
//            {
//                String s = dto.getConceptCode();
//                String s1 = "";//displayName目前没有值 //concept.getDescription().getTerm(); 
//                String cn = dto.getConceptName(); // ets术语名称 mCodeName
//                 
//                String s2 = dto.getVersionName();
//                String en = dto.getCodingschemeEnName(); //英文编码 mCodeSystemEnName
//                String ch = dto.getCodingschemeChName(); //中文编码 mCodeSystemChName
//                String s4 = dto.getCodingschemeOid();
//                ST st = STImpl.valueOf(s);
//                com.sunwayhorizo.health.hl7.datatypes.UID uid = UIDImpl.valueOf(s4);
//                ST sen = STImpl.valueOf(en); //对应com.sunwayhorizo.health.hl7.datatypes.common.CDImpl中的mCodeSystemEnName
//                ST sch = STImpl.valueOf(ch); //对应com.sunwayhorizo.health.hl7.datatypes.common.CDImpl中的mCodeSystemChName
//                ST scn = STImpl.valueOf(cn); //对应com.sunwayhorizo.health.hl7.datatypes.common.CDImpl中的mCodeName
//                ST st2 = STImpl.valueOf(s2);
//                ST st3 = STImpl.valueOf(s1);
//                CEImpl ceimpl = new CEImpl(etsservice, st, uid, sen,sch,scn, st2, st3, null, null);
//                ace[i] = ceimpl;
//            } else
//            {
//                throw new ETSNotFoundException("one or more of the ETS IDs not valid.");
//            }
//        }
//
//        return valueOf(ace);
//    }

    protected SET_CEImpl(CE ace[])
    {
        if(ace == null)
            throw ANYImpl.newNullException("SET<CE>", "constructor", "elements");
        for(int i = 0; i < ace.length; i++)
            if(ace[i] != null && ace[i].isNull().isFalse())
                mSet.add(ace[i]);

    }

    protected SET_CEImpl(CE ce)
    {
        if(ce == null || ce.isNull().isTrue())
        {
            throw ANYImpl.newNullException("SET<CE>", "constructor", "element");
        } else
        {
            mSet.add(ce);
            return;
        }
    }

    protected SET_CEImpl(CS cs)
    {
        super(cs);
    }

    private SET_CEImpl(Set set)
    {
        super(set);
    }

    public BL contains(CE ce)
    {
        return BLImpl.valueOf(mSet.contains(ce));
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.SET_CE;
    }

    public BL contains(SET_CE set_ce)
    {
        if(isNull().isTrue())
            return BLImpl.FALSE;
        else
            return BLImpl.valueOf(mSet.containsAll(set_ce.toSet()));
    }

    public SET_CE union(SET_CE set_ce)
    {
        if(isNull().isTrue())
            if(set_ce == null || set_ce.isNull().isTrue())
                return this;
            else
                return set_ce;
        if(set_ce.isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.addAll(set_ce.toSet());
            return new SET_CEImpl(hashset);
        }
    }

    public SET_CE union(CE ce)
    {
        if(ce == null || ce.isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.add(ce);
            return new SET_CEImpl(hashset);
        }
    }

    public SET_CE except(CE ce)
    {
        if(isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.remove(ce);
            return new SET_CEImpl(hashset);
        }
    }

    public SET_CE except(SET_CE set_ce)
    {
        if(set_ce == null || isNull().or(set_ce.isNull()).isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            Set set = set_ce.toSet();
            hashset.removeAll(set);
            return new SET_CEImpl(hashset);
        }
    }

    public SET_CE intersection(SET_CE set_ce)
    {
        if(set_ce == null || isNull().or(set_ce.isNull()).isTrue())
            return nullSET_CE();
        HashSet hashset = new HashSet();
        for(Iterator iterator = set_ce.toSet().iterator(); iterator.hasNext();)
        {
            CE ce = (CE)iterator.next();
            if(mSet.contains(ce))
                hashset.add(ce);
        }

        return new SET_CEImpl(hashset);
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof SET_CE))
            return BLImpl.FALSE;
        if(isNull().or(any.isNull()).isTrue())
        {
            return BLImpl.FALSE;
        } else
        {
            SET_CE set_ce = (SET_CE)any;
            BL bl = cardinality().equal(set_ce.cardinality());
            return bl.and(contains(set_ce));
        }
    }

    public IVL_CE hull()
    {
        throw ANYImpl.newUnsupportedException("SET<CE>", "hull");
    }

    protected boolean verifyItem(Object obj)
    {
        return (obj instanceof CE) && ((CE)obj).nonNull().isTrue();
    }

    public int hashCode()
    {
        return super.hashCode();
    }

    public static SET_CE nullSET_CE(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
